home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / programming / mui / mcc_transferanim / developer / c / examples / transferanim-demo.c
C/C++ Source or Header  |  1999-05-17  |  15KB  |  470 lines

  1. /***************************************************************************/
  2. /**                                                                       **/
  3. /**     TransferAnim-Demo, an example program for TransferAnim.mcc        **/
  4. /**                                                                       **/
  5. /**                                                                       **/
  6. /**     Feel free to use the source and please notify me about errors,    **/
  7. /**     bugs, good and bad things.                                        **/
  8. /**                                                                       **/
  9. /**     by Linus McCabe, sparkle@hehe.com                                 **/
  10. /**                      http://sparkle.amiga.tm                          **/
  11. /**                                                                       **/
  12. /***************************************************************************/
  13.  
  14. #define progname "TAnimExample"
  15. #define progbase "TANIME"
  16. #define vsion "V1.1 (15-May-99)"
  17.  
  18. #define aboutanim "mui:images/TransferAnim/aboutanim"
  19. #define aboutbutton "mui:images/TransferAnim/about"
  20. #define playbutton "mui:images/TransferAnim/play"
  21. #define stopbutton "mui:images/TransferAnim/stop"
  22. #define checkmark "mui:images/TransferAnim/checkmark"
  23. #define mainanim "mui:images/TransferAnim/mainanim"
  24.  
  25. /* System */
  26. #include <dos/dos.h>
  27. #include <workbench/workbench.h>
  28. #include <exec/memory.h>
  29. #include <libraries/mui.h>
  30. #include <datatypes/datatypes.h>
  31. #include <datatypes/pictureclass.h>
  32. #include <datatypes/PictureClassExt.h>
  33. #include <graphics/gfxmacros.h>
  34. #include <devices/timer.h>
  35. #include <libraries/asl.h>
  36. #include <mui/TransferAnim_mcc.h>
  37.  
  38. /* Prototypes */
  39.  
  40. #include <clib/alib_protos.h>
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/icon_protos.h>
  44. #include <clib/graphics_protos.h>
  45. #include <clib/intuition_protos.h>
  46. #include <clib/gadtools_protos.h>
  47. #include <clib/utility_protos.h>
  48. #include <clib/asl_protos.h>
  49. #include <clib/muimaster_protos.h>
  50. #include <clib/datatypes_protos.h>
  51. #include <clib/rexxsyslib_protos.h>
  52.  
  53. /* ANSI C */
  54. #include <stdlib.h>
  55. #include <string.h>
  56. #include <stdio.h>
  57.  
  58. #ifdef __SASC
  59. #include <pragmas/exec_sysbase_pragmas.h>
  60. #else
  61. #include <pragmas/exec_pragmas.h>
  62. #endif
  63. #include <pragmas/dos_pragmas.h>
  64. #include <pragmas/icon_pragmas.h>
  65. #include <pragmas/graphics_pragmas.h>
  66. #include <pragmas/intuition_pragmas.h>
  67. #include <pragmas/gadtools_pragmas.h>
  68. #include <pragmas/utility_pragmas.h>
  69. #include <pragmas/asl_pragmas.h>
  70. #include <pragmas/muimaster_pragmas.h>
  71. #include <pragmas/rexxsyslib_pragmas.h>
  72.  
  73. extern struct Library *SysBase, *IconBase, *IntuitionBase, *GfxBase, *UtilityBase, *DOSBase; 
  74. extern struct Library * MUIMasterBase, *RexxSysBase, *AslBase;
  75.  
  76. __saveds __asm VOID aboutmui(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  77. __saveds __asm VOID about(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  78. __saveds __asm VOID closeabout(register __a0 struct Hook *hook ,    register __a2 Object *appl ,    register __a1 APTR *args );
  79.  
  80.  
  81. struct Library * MUIMasterBase;
  82.  
  83.   /*************************/
  84.  /* Menues                */
  85. /*************************/
  86.  
  87. enum { MenQuit=1, MenAbout, MenAboutMUI, MenMUIPrefs};
  88.  
  89. static const struct NewMenu MenuData1[] =
  90. {
  91. { NM_TITLE, progname                   , 0 ,0 ,0             ,(APTR)0 },
  92. { NM_ITEM ,  "About"                   ,"?",0 ,0             ,(APTR)MenAbout },
  93. { NM_ITEM ,  "About MUI"               , 0 ,0 ,0             ,(APTR)MenAboutMUI },
  94. { NM_ITEM ,  NM_BARLABEL               , 0 ,0 ,0             ,(APTR)0 },
  95. { NM_ITEM ,  "Quit"                    ,"Q",0 ,0             ,(APTR)MenQuit },
  96.  
  97. { NM_TITLE, "Settings"                 , 0 ,0 ,0             ,(APTR)0 },
  98. { NM_ITEM ,  "Mui..."                  , 0 ,0 ,0             ,(APTR)MenMUIPrefs },
  99.  
  100. { NM_END,NULL,0,0,0,(APTR)0 }
  101. };
  102.  
  103.  
  104. /**** Hooks ***/
  105.  
  106. const struct Hook aboutmuiHook = {
  107.    {NULL,NULL},
  108.    (void *)aboutmui,
  109.    NULL,NULL
  110. };
  111.  
  112. const struct Hook aboutHook = {
  113.    {NULL,NULL},
  114.    (void *)about,
  115.    NULL,NULL
  116. };
  117.  
  118. const struct Hook closeAboutHook = 
  119. {
  120.     {NULL,NULL},
  121.     (void *)closeabout,
  122.     NULL,NULL
  123. };
  124.  
  125.  
  126.  
  127.  
  128. /*** Main code ***/
  129.  
  130. int main(int argc,char ** argv)
  131. {
  132.     
  133.     /** A few variables. ctrlwin = main window, app = application object
  134.         menustrip = the programs menue, titlewin = the 'open while loading' window.
  135.         about button is the programs only gadget. */
  136.     
  137.     Object * ctrlwin, *app, *menustrip, *TitleWin;
  138.     Object *AboutButton;
  139.     Object *play, *stop, *noloop, *mainanimobj, *prop;
  140.     
  141.     /* Open muimaster library */
  142.     
  143.       if (!(MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN)))
  144.     {
  145.         printf("Unable to open muimaster.library\n");
  146.         return(5);
  147.     }
  148.     
  149.     /* Create apploication object */
  150.     /* I chose to make this a small thing with only a simple window with a text.
  151.         This way I can open the window quickly to confirm that the program is started.
  152.         Especially when the 'real' main windows contains alot of datatypes and other
  153.         'slow' stuff this makes sence. And especially on slow machines. */
  154.         
  155.     app=ApplicationObject,
  156.         MUIA_Application_Title    , progname,
  157.         MUIA_Application_Version    , "$VER: "progname" "vsion,
  158.         MUIA_Application_Copyright  , "©1998, Linus McCabe.",
  159.         MUIA_Application_Author     , "Linus McCabe",
  160.         MUIA_Application_Description, "TransferAnim.mcc example.", 
  161.         MUIA_Application_Base       , progbase,
  162.         MUIA_Application_Menustrip     , menustrip=MUI_MakeObject(MUIO_MenustripNM,MenuData1,0),
  163.     
  164.         SubWindow,TitleWin=WindowObject,
  165.             MUIA_Window_SizeGadget,FALSE,
  166.             MUIA_Window_DragBar,FALSE,
  167.             MUIA_Window_CloseGadget,FALSE,
  168.             MUIA_Window_DepthGadget,FALSE,
  169.  
  170.             MUIA_Window_Activate,FALSE,
  171.  
  172.             WindowContents,
  173.                 VGroup,
  174.                     Child,TextObject,
  175.                         MUIA_Text_Contents,"TransferAnim.mcc, \nMUI Customclass by Linus McCabe",
  176.                     End,
  177.                 End,
  178.             End,
  179.         End;
  180.         
  181.         if(app)    /* If the application could be opened */
  182.         {
  183.             
  184.             /* Open the title window */
  185.             set(TitleWin, MUIA_Window_Open, TRUE);    
  186.             
  187.             /* Create main window */
  188.             ctrlwin=WindowObject,
  189.                 MUIA_Window_Title,progname" "vsion" by Linus McCabe",
  190.                 MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
  191.                 
  192.                 WindowContents,
  193.                     VGroup,
  194.                         MUIA_Background,"2:00000000,00000000,00000000",
  195.                         Child,HGroup,
  196.                             Child, mainanimobj=TransferAnimObject,
  197.                                 MUIA_TransferAnim_File, mainanim,
  198.                                 MUIA_InputMode,MUIV_InputMode_RelVerify,
  199.                             End,
  200.                             Child, TextObject,
  201.                                 MUIA_Text_SetMax,TRUE,
  202.                                 MUIA_Text_Contents,"\338"progname" "vsion"\nby Linus McCabe",
  203.                             End,
  204.                             Child, AboutButton=TransferAnimObject,
  205.                                             MUIA_TransferAnim_File,(ULONG) aboutbutton,
  206.                                             MUIA_TransferAnim_NoAnim,TRUE,
  207.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  208.                                             MUIA_TransferAnim_SelectedFrame,1,
  209.                                             MUIA_TransferAnim_DisabledFrame,2,
  210.                             End,
  211.                         End,
  212.                         Child, HGroup,
  213.                             Child, play=TransferAnimObject,
  214.                                             MUIA_TransferAnim_File,(ULONG) playbutton,
  215.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  216.                                             MUIA_TransferAnim_NoAnim,TRUE,
  217.                             End,
  218.                             Child, stop=TransferAnimObject,
  219.                                             MUIA_TransferAnim_File,(ULONG) stopbutton,
  220.                                             MUIA_InputMode,MUIV_InputMode_RelVerify,
  221.                                             MUIA_TransferAnim_NoAnim,TRUE,
  222.                             End,
  223.                             Child, noloop=TransferAnimObject,
  224.                                             MUIA_TransferAnim_File,(ULONG) checkmark,
  225.                                             MUIA_InputMode,MUIV_InputMode_Toggle,
  226.                                             MUIA_TransferAnim_NoAnim,TRUE,
  227.                             End,
  228.                             Child, prop=SliderObject,
  229.                                 MUIA_Group_Horiz, TRUE,
  230.                             End,
  231.                             
  232.                         End,
  233.                     End,
  234.                 End;
  235.     
  236.             if (ctrlwin)    /*If the creation was successful */
  237.             {
  238.                 
  239.                 ULONG tmp;
  240.                 
  241.                 /* add to application */
  242.                 DoMethod(app, OM_ADDMEMBER, ctrlwin);    
  243.     
  244.  
  245.             /*Main methods*/
  246.  
  247.             
  248.                 /* set up some basic notifiactions, closegadget, menues etc*/
  249.                 DoMethod(ctrlwin,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  250.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,MenQuit,app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  251.                 DoMethod(app,MUIM_Notify,MUIA_Application_MenuAction,